package com.ai.mall.controller.admin;

import com.ai.mall.entity.FlashSalesEntity;
import com.ai.mall.service.FlashSalesService;
import com.ai.mall.utils.PageUtils;
import com.ai.mall.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 秒杀活动表
 *
 * @author easue
 * @email sunlightcs@gmail.com
 * @date 2025-01-21 14:40:34
 */
@RestController
@RequestMapping("mall/flashsales")
public class FlashSalesController {
    @Autowired
    private FlashSalesService flashSalesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("mall:flashsales:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = flashSalesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{saleId}")
    //@RequiresPermissions("mall:flashsales:info")
    public R info(@PathVariable("saleId") Integer saleId){
		FlashSalesEntity flashSales = flashSalesService.getById(saleId);

        return R.ok().put("flashSales", flashSales);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("mall:flashsales:save")
    public R save(@RequestBody FlashSalesEntity flashSales){
		flashSalesService.save(flashSales);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("mall:flashsales:update")
    public R update(@RequestBody FlashSalesEntity flashSales){
		flashSalesService.updateById(flashSales);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("mall:flashsales:delete")
    public R delete(@RequestBody Integer[] saleIds){
		flashSalesService.removeByIds(Arrays.asList(saleIds));

        return R.ok();
    }

}
